#include "stdafx.h"
#include "ZMCommunicateMain.h"
#include "CommandDefine.h"
#include "NetManage.h"
#include "NetDataHander.h"
#include "NetHander.h"

SharedPointer<ZMCommunicateMain> ZMCommunicateMain::m_pCommunicateMain;
ZMCommunicateMain::ZMCommunicateMain()
{
}


ZMCommunicateMain::~ZMCommunicateMain()
{
}

void ZMCommunicateMain::Start(ZMString strIP, ZMString iPort)
{
	m_pNetMain = SharedPointer<CNetSevice>(new CNetSevice(strIP, iPort));
	m_pNetMain->Start();
}

void ZMCommunicateMain::WriteData(const ZMVector<unsigned char>& data, emDevice idDeviceType, emFnc cFunc, int idDevice)
{
	SharedPointer<ZMVector<unsigned char>> pData = CCommandDefine::InitData(idDevice, idDeviceType, cFunc, data);
	if (idDeviceType == DEVICE_UNITY3D)
	{
		CNetConnectManage::GetInstance()->PushNewDataWrite(pData);
	}
	if (idDeviceType == DEVICE_QT || idDeviceType == DEVICE_OGRE)
	{
		CNetDataHander::GetInstance()->DataCommit(pData);
	}
}